home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Into His Marvelous Light
/
Into His Marvelous LIGHT.iso
/
lesson2.dxr
/
00324_Script_Color Cycling
< prev
next >
Wrap
Text File
|
1998-01-03
|
10KB
|
247 lines
-- Color Cycling
-- Animates the color of a sprite over time.
-- v1 by Darrel Plant
on getBehaviorDescription
vDesc = "COLOR CYCLING" & RETURN & RETURN
vDesc = vDesc & "Use this behavior to create a color animation effect. The"
vDesc = vDesc && "sprite will change over a period of time, from one color"
vDesc = vDesc && "to another. Use color indices from the movie palette or"
vDesc = vDesc && "RGB color values. The speed of the color cycle can be set,"
vDesc = vDesc && "as can the number of time the colors cycle. To make the"
vDesc = vDesc && "color change once (from the start color to the end color)"
vDesc = vDesc && "set the number of cycles to 0, choose -1 to cycle forever."
vDesc = vDesc & RETURN& RETURN & "PARAMETERS:" & RETURN
vDesc = vDesc & " - Color mode (RGB or palette index)"
vDesc = vDesc & RETURN & " - Time period (seconds) for each change of colors"
vDesc = vDesc & RETURN & " - Number of cycles" & RETURN
vDesc = vDesc & " - Settings for start color" & RETURN
vDesc = vDesc & " - Settings for end color"
return vDesc
end getBehaviorDescription
on getBehaviorTooltip me
vTip ="Cycles a sprite's colors through either the"&RETURN
vTip = vTip & "RGB or Indexed color mode. Cycling can be"&RETURN
vTip = vTip & "continuous or for a specific number of cycles."&RETURN
vTip = vTip & "The cycle rate can also be set."
return vTip
end getBehaviorTooltip
-- PROPERTIES --
property pSprite -- sprite object reference
property pColorStart -- color object for start of cycle
property pColorEnd -- color object for end of cycle
property pCycleStart -- time current color change started
property pCycleEnd -- time current color change ends
property pColorRDiff -- difference in start and end red
-- -- or palette index values
property pColorGDiff -- difference in green values
property pColorBDiff -- differencein blue values
property pCycleMillis -- color change period in milliseconds
property pCyclesComplete -- number of complete color cycles
-- author-defined properties
property pColorMode -- flag for RGB or palette index
property pCyclePeriod -- color change period in seconds
property pColorCycles -- number of color cycles to complete
property pColor1R -- red component or palette index
-- -- of start color
property pColor1G -- green component of start color
property pColor1B -- blue component of start color
property pColor2R -- red component or palette index
-- -- of end color
property pColor2G -- green component of end color
property pColor2B -- blue component of end color
-- EVENT HANDLERS --
on beginSprite me
mInitialize me
end beginSprite
on prepareFrame me
mUpdate me
end prepareFrame
-- CUSTOM HANDLERS --
on mInitialize me
-- cache sprite object
pSprite = sprite (me.spriteNum)
-- initialize number of cycles
pCyclesComplete = 0.5
-- convert author-set period to milliseconds
pCycleMillis = integer (pCyclePeriod * 1000)
-- set up first color change
mInitColors me
end mInitialize
on mUpdate me
-- determine current time
vTime = the milliseconds
-- determine time elapsed in current color change
vElapsed = vTime - pCycleStart
-- check whether color change should be complete
if vTime >= pCycleEnd then
-- set sprite color to color at end of change
pSprite.color = pColorEnd
-- increment cycle counter
pCyclesComplete = pCyclesComplete + 0.5
-- start new color change, depending on
-- setting for number of cycles
case pColorCycles of
-- continuous cycling, automatically start change
-1: mInitColors me
-- single color change, no more changes
0: nothing
otherwise
-- a limited number of cycles requires a test
-- so see whether the required cycles have been
-- completed, if not, then start new change
if pCyclesComplete <= pColorCycles then
mInitColors me
end if
end case
else
-- determine whether colors are set using RGB or palette index values
if pColorMode = #rgb then
-- determine current color component values based on percentage of
-- time allocated to change that has elapsed multiplied by the
-- difference between the start and end color components for
-- red, green, and blue
vRed = pColorStart.red + pColorRDiff * vElapsed / pCycleMillis
vGreen = pColorStart.green + pColorGDiff * vElapsed / pCycleMillis
vBlue = pColorStart.blue + pColorBDiff * vElapsed / pCycleMillis
-- create RGB color object from current color component values and
-- assign to sprite
pSprite.color = rgb (vRed, vGreen, vBlue)
else
-- palette index color mode uses only one of the color values,
-- ignoring whatever settings may exist for green and blue
vRed = pColorStart.paletteIndex + pColorRDiff * vElapsed / pCycleMillis
-- create palette index color object from current color component values
-- and assign to sprite
pSprite.color = paletteIndex (vRed)
end if
end if
end mUpdate
on mInitColors me
-- creates a new color change by deciding which portion off the color
-- cycle is being represented, setting up start and end colors, and
-- establishing timing information
-- when the pCompletedCycles property is 0.5, 1.5, 2.5, etc., this
-- test evaluates TRUE
if integer (pCyclesComplete * 2) <> integer (pCyclesComplete) * 2 then
-- change color from first color to second color
vStartColorList = [pColor1R, pColor1G, pColor1B]
vEndColorList = [pColor2R, pColor2G, pColor2B]
else
-- change color from second color to first color
vStartColorList = [pColor2R, pColor2G, pColor2B]
vEndColorList = [pColor1R, pColor1G, pColor1B]
end if
-- set up color objects for start and end colors, depending on setting
-- for the color mode
if pColorMode = #rgb then
-- create RGB color objects
pColorStart = ¼
rgb (vStartColorList[1], vStartColorList[2], vStartColorList[3])
pColorEnd = rgb (vEndColorList[1], vEndColorList[2], vEndColorList[3])
else
-- create palette index color objects
pColorStart = paletteIndex (vStartColorList[1])
pColorEnd = paletteIndex (vEndColorList[1])
end if
-- determine differences in color components
pColorRDiff = vEndColorList [1] - vStartColorList[1]
pColorGDiff = vEndColorList [2] - vStartColorList[2]
pColorBDiff = vEndColorList [3] - vStartColorList[3]
-- set time color change began
pCycleStart = the milliseconds
-- add cycle period to determine when change should end
pCycleEnd = pCycleStart + pCycleMillis
-- set the sprite to the current start color
pSprite.color = pColorStart
end mInitColors
-- ERROR CHECKING --
on mErrorAlert me, vError, vData
-- based on James Newton's error checking procedure
-- determine name of behavior
vBehaviorname = string (me)
delete word 1 of vBehaviorName
delete the last word of vBehaviorName
delete the last word of vBehaviorName
-- convert supporting data
case vData.ilk of
#void: vData = "<void>"
#symbol: vData = "#" & vData
end case
case vError of
-- deal with individual error types
#getPDLError: -- error from property dialog
beep
return [#getPDLError: [#comment: ¼
"CANCEL: Sprite MUST be one of the following member types:" ¼
& RETURN & vData, #format: #symbol, ¼
#range: [#Cancel], #default: #Cancel]]
end case
end mErrorAlert
-- AUTHOR-DEFINED PARAMETERS --
on getPropertyDescriptionList me
if not the currentSpriteNum then
-- behavior has been attached to script channel
exit
end if
vRect = the stage.rect
vMemberType = sprite (the currentSpriteNum).member.type
if not getPos (mPermittedMemberTypes (), vMemberType) then
return mErrorAlert (me, #getPDLError)
end if
vColor = sprite (the currentSpriteNum).color
vColorType = vColor.colorType
if vColorType = #rgb then
vRed = vColor.red
vGreen = vColor.green
vBlue = vColor.blue
else
vRed = vColor.paletteIndex
vGreen = 0
vBlue = 0
end if
vPDList = [:]
setaProp vPDList, #pColorMode, [#comment: "Color mode", ¼
#format: #symbol, #default: #palette, #range: [#palette, #RGB]]
setaProp vPDList, #pCyclePeriod, [#comment: "Cycle period (seconds)", ¼
#format: #float, #default: 3, #range: [#min: 1, #max: 25]]
setaProp vPDList, #pColorCycles, [#comment: "Color cycles", ¼
#format: #integer, #default: 0, #range: [#min: -1, #max: 100]]
setaProp vPDList, #pColor1R, ¼
[#comment: "Start color: palette index or Red component", ¼
#format: #integer, #default: vRed, #range: [#min: 0, #max: 255]]
setaProp vPDList, #pColor1G, ¼
[#comment: "Green component", ¼
#format: #integer, #default: vGreen, #range: [#min: 0, #max: 255]]
setaProp vPDList, #pColor1B, ¼
[#comment: "Blue component", ¼
#format: #integer, #default: vBlue, #range: [#min: 0, #max: 255]]
setaProp vPDList, #pColor2R, ¼
[#comment: "Final color: palette index or Red component", ¼
#format: #integer, #default: 255 - vRed, #range: [#min: 0, #max: 255]]
setaProp vPDList, #pColor2G, ¼
[#comment: "Green component", ¼
#format: #integer, #default: 255 - vGreen, #range: [#min: 0, #max: 255]]
setaProp vPDList, #pColor2B, ¼
[#comment: "Blue component", ¼
#format: #integer, #default: 255 - vBlue, #range: [#min: 0, #max: 255]]
return vPDList
end getPropertyDescriptionList
on mPermittedMemberTypes me
return [#bitmap, #flash, #animgif, #shape, #text]
end mPermittedMemberTypes